﻿// This code is released under the BSD license.
namespace PugLib.UnitTest
{
    #region

    using System;
    using System.Threading;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    #endregion

    /// <summary>
    ///This is a test class for RepeatTest and is intended
    ///to contain all RepeatTest Unit Tests
    ///</summary>
    [TestClass]
    public class RepeatTest
    {
        /// <summary>
        ///A test for Call
        ///</summary>
        [TestMethod]
        public void CallTest()
        {
            Repeat.Call(() => Console.WriteLine("Hello World!")).Start(10);
            Repeat.Call(Pinger).PauseBetweenCalls(20).Start(10);
            Repeat.Call<string>(Save).WithParameters("myfile.txt").UntilSucceeds.Start(10);
            Repeat.Call(Open).InBackgroundThread.At(ThreadPriority.Lowest).OnSuccessCall(Opened).OnExceptionCall(Failed)
                .Start();
        }

        private static void Open()
        {
            // Open the file
        }

        private static void Opened()
        {
            // The file opened
        }

        private static void Failed(Exception ex)
        {
            // Exception ex has been thrown
        }

        private static void Pinger()
        {
        }

        private static void Save(string fileName)
        {
            // Do the saving
        }
    }
}